package cn.edu.neusoft.zengweidong707.neufood.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import cn.edu.neusoft.zengweidong707.neufood.R;

public abstract class BaseActivity extends AppCompatActivity {
    protected int layout_file = R.layout.activity_main;
    private SharedPreferences sp;

    abstract void initView();
    abstract void initEvent();
    abstract void initData();

    public void setLayout_file(int layout_file) {
        setContentView(layout_file);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setLayout_file(layout_file);
        initView();
        initEvent();
        initData();
    }
    protected String getUsername() {
        sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        return sp.getString("username", "");
    }

    protected String getUserpass() {
        sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        return sp.getString("userpass", "");
    }

    protected String getUserid() {
        sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        return sp.getString("userid", "");
    }

    protected boolean getRemember() {
        sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        return sp.getBoolean("remember", false);
    }

    protected void showToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
}
